// pages/lawyer/lawyer.js

import config from './../../config';
import {
    empty,
    message,
    session,
    getOpenId
} from './../../utils/helper';
import {
    getLawyerInfo,
} from './../../services/lawyer';
import qs from 'qs';

//获取应用实例
const app = getApp();
//实例化本地缓存
const cookie = new session();

const host = config.service.transfer_protocol + '://' + config.service.domain;

Page({

    /**
     * 页面的初始数据
     */
    data: {
        info: {},
        host: host
    },

    //父级页面传递过来的表单参数
    params: {},

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        let that = this;
        //显示当前页面的转发按钮
        wx.showShareMenu({
            withShareTicket: true
        });
        if (empty(options)) {
            console.warn('同学：你这个样子直接打开，是木有办法提交的表单的！');
        } else {
            this.params = options;
            getLawyerInfo(this.params, {
                success: ({
                    data
                }) => {
                    that.setData({
                        info: data
                    });
                    wx.setNavigationBarTitle({
                        title: data.name + '律师'
                    })
                }
            });
        }
    },

    fufei(){
        wx.navigateTo({
            url: '/pages/consult/consult?' + qs.stringify(this.params),
        })
    },

    //下拉刷新事件
    onPullDownRefresh() {
        this.onLoad();
        wx.stopPullDownRefresh();
    },

    //转发小程序函数
    onShareAppMessage: function(res) {
        let p;
        if (this.data.info.lawyer_extend.share_img_pic) {
            p = {
                title: this.data.info.lawyer_extend.share_title ? this.data.info.lawyer_extend.share_title :'分享给你一个专业律师，法律问题可以找他',
                path: '/pages/lawyer/lawyer?lawyer_id=' + this.data.info.id,
                imageUrl: host + this.data.info.lawyer_extend.share_img_pic
            }
        } else {
            p = {
                title: this.data.info.lawyer_extend.share_title ? this.data.info.lawyer_extend.share_title : '分享给你一个专业律师，法律问题可以找他',
                path: '/pages/lawyer/lawyer?lawyer_id=' + this.data.info.id
            }
        }
        return p;
    },
})